package com.aitemv.services.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.aitemv.base.impl.BaseServiceImpl;
import com.aitemv.entity.RoleTreeEntity;
import com.aitemv.services.RoleTreeService;
import com.aitemv.services.sqlMap.RoleTreeSqlMap;
import com.aitemv.vo.RoleTreeVo;
/**
 * @ClassName: RoleTreeServiceImpl 
 * @Description: 权限查询的service类
 * @author java_lyvee@126.com 
 * @date 2014-1-13 上午11:44:29 
 */
@Service
public class RoleTreeServiceImpl extends BaseServiceImpl implements RoleTreeService  {
	@Override
	public List<RoleTreeVo> qeuryFoList(RoleTreeEntity entity) {
		Map<String, Object> map;
		map = new HashMap<String, Object>();
		map.put("parentId", entity.getParentId());
		String sql = RoleTreeSqlMap.getInstanceSqlMap().conditionSql(entity,map).toString();
		String sqlQuerySub = "";
		@SuppressWarnings("unchecked")
		List<RoleTreeEntity> list = (List<RoleTreeEntity>) baseDao.getObjList(sql, entity.getClass(),  new Object[]{entity.getParentId()});
		List<RoleTreeVo> voList =  new ArrayList<RoleTreeVo>();
		RoleTreeVo rtvo;
		for (RoleTreeEntity entityTemp:list) {
			map = new HashMap<String,Object>();
			rtvo = new RoleTreeVo();
			rtvo.setId(entityTemp.getId());
			rtvo.setText(entityTemp.getTreeName());
			rtvo.setEname(entityTemp.getTreeEname());
			rtvo.setNodeUrl(entityTemp.getTreeUrl());
			map.put("parentId",entityTemp.getId());
			sqlQuerySub = RoleTreeSqlMap.getInstanceSqlMap().conditionSql(entityTemp, map,"").toString();
			int k  = baseDao.isExist(sqlQuerySub, new Object[]{entityTemp.getId()});
			if(k>0){
				rtvo.setLeaf(false);
			}else {
				rtvo.setLeaf(true);
			}
			voList.add(rtvo);
		}
		return voList;
	}

}
